package registnet.base;

import java.util.List;
import java.util.Vector;

import registnet.base.courseoffering.CourseOffering;
import registnet.dao.CoursePeer;

/**
 * An implementation of a course.
 */
public class Course extends AbstractCourse {

	/**
	 * The float constant used in the computation of the rank of the course.
	 */
	public static final float CONSTANT = 10;
	
	/**
	 * The total class hours of the course.
	 */
	private int classHours;
	
	/**
	 * The list of course offerings for the course.
	 */
	private List<CourseOffering> courseOfferings;
	
	/**
	 * Default constructor which creates an "empty" course.
	 */
	public Course(){
		courseCode = "";
		courseName = "";
		prerequisites = new Vector<Prerequisite>(); 
		unit = 0;
		semester = 0;
		year = 0;
		courseOfferings = new Vector<CourseOffering>();
	}
	
	/**
	 * Creates a course with the given description.
	 * @param courseCode
	 */
	public Course(String courseCode){
		this.courseCode = courseCode;
		courseName = "";
		prerequisites = new Vector<Prerequisite>(); 
		unit = 0;
		semester = 0;
		year = 0;
		courseOfferings = new Vector<CourseOffering>();
	}
	
	/**
	 * Checks if a course with the given code is offered for the given semester.
	 * @param courseCode
	 * @param semester
	 * @return true if a course with the given code is offered for the given semester
	 */
	public static boolean isOffered(String courseCode, int semester){
		String semOffered = new CoursePeer().getCourse(courseCode).getSemesterOffered();
		if(semOffered.contains(Integer.toString(semester)))
			return true;
		return false;
	}
	
	/**
	 * Computes the rank of the course
	 */
	public void computeRank(){
		rank = (int)(CONSTANT * (courseOfferings.size()/classHours));
	}

	/**
	 * Returns the total class hours of the course.
	 * @return the total class hours of the course.
	 */
	public int getClassHours() {
		return classHours;
	}

	/**
	 * Sets the total class hours of the course.
	 * @param classHours
	 */
	public void setClassHours(int classHours) {
		this.classHours = classHours;
	}
	
	/**
	 * Sets the list of course offerings for the course.
	 * @param courseOfferings
	 */
	public void setCourseOfferings(List<CourseOffering> courseOfferings){
		this.courseOfferings = courseOfferings;
	}
	
	/**
	 * Returns the list of course offerings for the course.
	 * @return the list of course offerings for the course.
	 */
	public List<CourseOffering> getCourseOfferings(){
		return courseOfferings;
	}
	
	
}
